#!/usr/bin/python

import time, sys
from math import sqrt, ceil, floor

""" 
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million    
"""

def isprime(num):
    ans = True
    if num <= 1:
        return False
    if num == 2:
        return True
    for n in xrange(2, int(ceil(sqrt(num)))+1):
        if num % n == 0:
            ans = False
            break

    return ans

def main():
    start = time.time()
    
    upper = 2e6
    sum = 0
    n = 2
    
    while n < upper:
        if isprime(n) is True:
            if n < 10:
                print n
            sum += n
            if n == 7:
                print 'sum = {0}'.format(sum) 
        n += 1
    
    print 'n = {1}, sum = {0}'.format(sum, n)    
    print '{0:.2f} s'.format(time.time() - start)        
# the sum of primes up to 2 million is 142913828922
# 16.22 s

if __name__ == '__main__':
  main()
